<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:v="http://corejsf.com/validator">

    <f:view>
        <f:loadBundle var="text" basename="#{remissionForm.bundleName}"/>        
        <head>
            <title>#{text['remissionDetail.title']}</title>
            <meta name="heading" content="#{text['remissionDetail.heading']}"/>
            <meta name="menu" content="OperationMenu"/>
        </head>

        <div class="separator"></div>

        <h:form id="remissionForm">
            <h:inputHidden value="#{remissionForm.remission.id}" id="id"/>

            <h:panelGrid columns="3">

                <h:panelGroup styleClass="buttonBar right">
                    <h:commandButton value="#{text['button.save']}" action="#{remissionForm.save}" id="save" styleClass="button"/>
                    <c:if test="${not empty remissionForm.remission.id}">
                        <h:commandButton id="print" value="#{text['button.print']}"
                                         onclick="return printRemission('rpt_remisiones.rptdesign',#{remissionForm.remission.id});"
                                         styleClass="button"/>
                    </c:if>
                    <h:commandButton value="#{text['button.cancel']}" action="cancel" immediate="true"
                                     id="cancel" styleClass="button"/>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="_id" value="#{text['remission.id']}"/>
                            <h:inputText styleClass="text medium" id="_id" value="#{remissionForm.remission.id}" readonly="true"/>
                            <t:message for="_id" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="quotation" value="#{text['remission.quotation']}"/>
                            <h:inputText styleClass="text medium" id="quotation" value="#{remissionForm.remission.workOrder.quotation.id}" readonly="true"/>
                            <t:message for="quotation" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>

                <h:outputText/><h:outputText/>

                <h:outputLabel for="description" styleClass="desc" value="#{text['remission.description']}"/>
                <t:message for="description" styleClass="fieldError"/>
                <h:inputText value="#{remissionForm.remission.description}" id="description" readonly="true" styleClass="text large">
                    <v:commonsValidator client="true" type="required" arg="#{text['remission.description']}"/>
                </h:inputText>

                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="date" value="#{text['remission.date']}"/>
                            <h:inputText styleClass="text medium" id="date" value="#{remissionForm.remission.date}" readonly="true">
                                <f:convertDateTime pattern="dd/MM/yyyy"/>
                            </h:inputText>
                            <t:message for="date" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="createdOn" value="#{text['remission.createdOn']}"/>
                            <h:inputText styleClass="text medium" id="createdOn" value="#{remissionForm.remission.createdOn}" readonly="true">
                                <f:convertDateTime pattern="dd/MM/yyyy"/>
                            </h:inputText>
                            <t:message for="createdOn" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>

                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="woEmployee" value="#{text['workOrder.employee']}"/>
                            <h:inputText styleClass="text medium" id="woEmployee" value="#{remissionForm.remission.workOrder.employee.firstName}" readonly="true"/>
                            <t:message for="woEmployee" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="employee" value="#{text['remission.employee']}"/>
                            <h:selectOneMenu value="#{remissionForm.remission.employee}" id="responsible" required="true" styleClass="select">
                                <t:selectItems value="#{remissionForm.responsibles}" var="responsible" itemLabel="#{responsible.firstName} #{responsible.lastName}" itemValue="#{responsible}"/>
                                <f:converter converterId="objconverter"/>
                                <v:commonsValidator client="true" type="required" arg="#{text['remission.employee']}"/>
                            </h:selectOneMenu>
                            <t:message for="employee" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>

                <h:outputText/><h:outputText/>

                <t:dataTable value="#{remissionForm.remission.details}" var="detail" width="100%" id="_products"
                             styleClass="scrollerTable table">
                    <f:facet name="spacer">
                        <f:verbatim>&amp;#160;</f:verbatim>
                    </f:facet>
                    <t:column width="40%">
                        <f:facet name="header">
                            <t:outputText value="#{text['remissionDetail.product.description']}"/>
                        </f:facet>
                        <t:outputText value="#{detail.quotationDetail.product.description}" rendered="#{detail.quotationDetail.product != null}"/>
                        <t:outputText value="#{detail.quotationDetail.itemDescription}" rendered="#{detail.quotationDetail.product == null}"/>
                    </t:column>
                    <t:column width="30%">
                        <f:facet name="header">
                            <t:outputText value="#{text['product.resolution']}"/>
                        </f:facet>
                        <t:outputText value="#{detail.quotationDetail.product.resolution.description}"/>
                    </t:column>
                    <t:column width="30%">
                        <f:facet name="header">
                            <t:outputText value="#{text['product.workType']}"/>
                        </f:facet>
                        <t:outputText value="#{detail.quotationDetail.product.workType.description}"/>
                    </t:column>
                </t:dataTable>

                <h:outputText/><h:outputText/>

                <h:outputLabel for="notes" styleClass="desc" value="#{text['remission.notes']}"/>
                <t:message for="notes" styleClass="fieldError"/>
                <h:inputText value="#{remissionForm.remission.notes}" id="notes" styleClass="text large"/>
            </h:panelGrid>
            <t:saveState id="save1" value="#{remissionForm.remission}" />
        </h:form>

        <script type="text/javascript">
            Form.focusFirstElement($('remissionForm'));
            highlightFormElements();
        </script>
        <script type="text/javascript">
            function printRemission(report, id){
                window.open('/birt-viewer/run?__report=' + report + '&amp;rp_remision=' + id + '__format=html','SuArte','height=700,width=800,status=yes,toolbar=no,menubar=yes,location=no,resizable=yes');
                return false;
            }
        </script>
    </f:view>
</html>